package com.itheima.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.mapper.BrandMapper;
import com.itheima.pojo.Brand;
import com.itheima.service.BrandService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Arrays;
import java.util.List;

@Slf4j
@Service
public class BrandServiceImpl implements BrandService {
    @Autowired
    private BrandMapper brandMapper;

    /**
     * 带条件查询所有的方法
     * @param brand
     * @return
     */
    @Override
    public List<Brand> selectAll(Brand brand) {
        return brandMapper.selectAll(brand);
    }
    /**
     * 添加品牌信息
     * @param brand
     */
    @Override
    public void add(Brand brand) {
        brandMapper.add(brand);
    }
	/**
     * 修改品牌信息
     * @param brand
     */
	 @Override
    public void update(Brand brand) {
	     brandMapper.update(brand);
     }
    /**
     * 批量删除
     * @param ids
     */
    @Override
    public void deleteByIds( int[] ids) {
        brandMapper.deleteByIds(ids);
    }

    /**
     * 带条件分页查询的方法
     * @param currentPage
     * @param pageSize
     * @param brand
     * @return
     */
    @Override
    public PageInfo<Brand> selectByPage(int currentPage, int pageSize, Brand brand) {
        //设置分页参数
        PageHelper.startPage(currentPage,pageSize);
        //执行操作
        List<Brand> list = brandMapper.selectAll(brand);
        //封装分页结果
        return new PageInfo<>(list);
    }
}
